//
//  AweakController.m
//  UIA段项目 墨家天气
//
//  Created by dllo on 15/8/27.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AweakController.h"
#import "AweakCell.h"
#import "UIImageView+WebCache.h"
@interface AweakController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,retain)UIView *headerView;
@property (nonatomic,retain)UIScrollView *sc;
@property (nonatomic,retain)UILabel *line;
@property (nonatomic,assign)CGFloat a;
@property (nonatomic,retain)UILabel *date;
@property (nonatomic,retain)UILabel *wind;
@end

@implementation AweakController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addCollectionView];
    [self addHeaderView];

}
-(void)dealloc
{
    [_aWeakArr release];
    [_headerView release];
    [_line release];
    [_date release];
    [_wind release];
    [super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
    self =  [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.aWeakArr = [NSMutableArray array];
        self.date = [[UILabel alloc]initWithFrame:CGRectMake(10 * OffWidth, 100 * OffHeight, 100 * OffWidth, 100 * OffHeight)];
        [_date release];
        self.wind = [[UILabel alloc]initWithFrame:CGRectMake(110 * OffWidth,540 * OffHeight, 300 * OffWidth,60 * OffHeight)];
        [_wind release];
    }
    
    return self;
}


- (void)addCollectionView
{
    
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    flow.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    [flow setMinimumLineSpacing:0];
    flow.scrollDirection =  UICollectionViewScrollDirectionHorizontal;
    UICollectionView *collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flow];
    
    collect.delegate = self;
    collect.dataSource = self;
    collect.pagingEnabled = YES;
    
  
    
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [imageV sd_setImageWithURL:self.backImageStr];
    [collect setBackgroundView:imageV];
    
    UIBlurEffect *ef = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effV = [[UIVisualEffectView alloc]initWithEffect:ef];
    effV.alpha = 0.9;
    effV.frame = [UIScreen mainScreen].bounds;
    [imageV addSubview:effV];

   
    [collect registerClass:[AweakCell class] forCellWithReuseIdentifier:@"fd"];
    collect.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
    [self.view addSubview:collect];
    
    [collect release];
    [imageV release];
//    [effV release];
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    AweakCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"fd" forIndexPath:indexPath];
    
   
    
    if (cell == nil) {

    }

    self.date.text = [[self.aWeakArr objectAtIndex:indexPath.item] objectForKey:@"dateName"];
    _date.font = [UIFont boldSystemFontOfSize:20 * OffWidth];
    _date.textColor = [UIColor whiteColor];

    [self.view addSubview:_date];
    self.wind.text = [[[self.aWeakArr objectAtIndex:indexPath.item]  objectForKey:@"winds"] objectForKey:@"direction"];
    self.wind.textColor = [UIColor whiteColor];
    self.wind.font = [UIFont boldSystemFontOfSize:30 * OffWidth];
    self.wind.textAlignment = 1;
    [self.view addSubview:_wind];

    
  
   
    NSInteger j1 =[[[[self.aWeakArr objectAtIndex:indexPath.item]objectForKey:@"climate"] objectForKey:@"id"] integerValue];
    cell.yunDayImage.image = [self panduanTianQi:j1];
    
    NSInteger j2 = [[[[self.aWeakArr objectAtIndex:indexPath.item] objectForKey:@"nightClimate"] objectForKey:@"id"] integerValue];
    cell.yunNightImage.image = [self panduanTianQi:j2];
    
    
    cell.date.text =  [[self.aWeakArr objectAtIndex:indexPath.item] objectForKey:@"date"];
    cell.high.text = [[[[self.aWeakArr objectAtIndex:indexPath.item] objectForKey:@"temp"] objectForKey:@"height"] stringValue];
    cell.low.text =  [[[[self.aWeakArr objectAtIndex:indexPath.item] objectForKey:@"temp"] objectForKey:@"low"] stringValue];
    

    cell.lowDu.text = @"。";
    cell.highDu.text = @"。";
    return cell;
    
   
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}


- (void)addHeaderView
{
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0 * OffWidth, self.view.frame.size.width, 60 * OffHeight)];
    _headerView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];

    [self.view addSubview:_headerView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,60 * OffHeight, self.view.frame.size.width, self.view.frame.size.height )];
    view.backgroundColor = [UIColor whiteColor];
    
    
    [self.view addSubview:view];
    [UIView animateWithDuration:2 animations:^{
        
        view.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.01];
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
        
        
    }];


    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 20 * OffHeight, 60 * OffWidth, 50 * OffHeight);
    [button setTitle:@" 返回" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:button];
    
    UILabel *cityName = [[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 200 * OffWidth) / 2, 20 * OffHeight, 200 * OffWidth, 50 * OffHeight)];
    cityName.textColor = [UIColor whiteColor];
    cityName.text = self.cityName;
    cityName.textAlignment = 1;
    cityName.font = [UIFont systemFontOfSize:20 * OffWidth];
    [self.view addSubview:cityName];
    
}



- (void)click:(UIButton *)button
{
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (UIImage *)panduanTianQi:(NSInteger )jjj
{
    if (jjj == 1) {
        UIImage *imagee = [UIImage imageNamed:@"qing.png"];
        return imagee;
    }else if (jjj == 2){
        UIImage *imagee = [UIImage imageNamed:@"duoyun.png"];
        return imagee;
    }else if (jjj == 3){
        UIImage *imagee = [UIImage imageNamed:@"yin"];
        return imagee;
    }else if (jjj == 4){
        UIImage *imagee = [UIImage imageNamed:@"xiaoyu.png"];
        return imagee;
    }else{
        UIImage *imagee= [UIImage imageNamed:@"baoyu.png"];
        return imagee;
    }
    
}


@end
